#!/usr/bin/perl
#edit_interface.cgi

require './network-lib.pl';
&ReadParse();

if(!defined($in{'eth'}))
{
	error($text{'no_interface'});	
}
my $b = &get_interface($in{'eth'});
if($b eq "")
{
	error($text{'interface_not_exist'});
}
if($b->{'virtual'} eq "")
{
&header($text{'edit_interface_title'}, "", "editinterface", 0, 1);
#print "<hr>\n";
print "<form action=save_interface.cgi method=post onsubmit='document.forms[0].savebtn.disabled = true;'>\n";
print "<input type=hidden name=eth value='$in{'eth'}'>\n";
print "<table class=mode1 border=0 cellspacing=0 cellpadding=4>\n";
print "<tr><td><b>$text{'ifcs_name'}</b></td>\n";
print "<td>", &get_adaptername($b->{'irq'}), "</td> </tr>\n";
print "<tr><td><b>$text{'ifcs_mac'}</b></td>\n";
print "<td>$b->{'ether'}</td> </tr>\n";
print "<tr><td><b>$text{'ifcs_ip'}</b></td>\n";
printf "<td><input type=radio name=iprdn %s value='dhcp' onclick='onclick_disable_txt();'>$text{'from_dhcp'}</td> </tr>\n", ($b->{'dhcp'})?"checked":"";
printf "<tr><td></td><td><input type=radio name=iprdn %s value='bootp' onclick='onclick_disable_txt();'>$text{'from_bootp'}</td> </tr>\n", ($b->{'bootp'})?"checked":"";
printf "<tr><td></td><td><input type=radio name=iprdn %s value='static' onclick='onclick_enable_txt();'><input class=text name=ipin value='$b->{'address'}' %s></td> </tr>\n", ((!$b->{'dhcp'})&&!($b->{'bootp'}))?"checked":"",((!$b->{'dhcp'})&&!($b->{'bootp'}))?"":"disabled";
print "<tr><td><b>$text{'ifcs_mask'}</b></td>\n";
printf "<td><input class=text name=maskin size=25 value='$b->{'netmask'}' %s></td> </tr>\n",((!$b->{'dhcp'})&&!($b->{'bootp'}))?"":"disabled";
#print "<tr><td><b>$text{'ifcs_broadcast'}</b></td>\n";
#print "<td><input class=text name=broadcastin size=25 value='$b->{'broadcast'}'></td> </tr>\n";
#print "<tr><td><b>$text{'ifcs_gateway'}</b></td>\n";
#printf "<td><input class=text name=gatewayin size=25 value='$b->{'gateway'}'></td> </tr>\n",((!$b->{'dhcp'})&&!($b->{'bootp'}))?"":"disabled";
print "<tr><td colspan=2><input class=button1 type=submit name=savebtn value='$text{'submit'}'></td></tr>\n";
print "</table></form>\n";
#print "<hr>\n";
print <<EOF;
<script>
function onclick_disable_txt()
{
        document.forms[0].ipin.disabled = true;
        document.forms[0].maskin.disabled = true;
//        document.forms[0].gatewayin.disabled = true;
}
function onclick_enable_txt()
{
        document.forms[0].ipin.disabled = false;
        document.forms[0].maskin.disabled = false;
//        document.forms[0].gatewayin.disabled = false;
}
</script>
EOF
&footer("index.cgi", $text{'interface_return'});
}
elsif($b->{'virtual'} eq "MASTER")
{
&header($text{'edit_interface_title'}, "", "editinterface", 0, 1);
print "<form action=save_interface.cgi method=post onsubmit='document.forms[0].savebtn.disabled = true;'>\n";
print "<input type=hidden name=eth value='$in{'eth'}'>\n";
print "<table class=mode1 border=0 cellspacing=0 cellpadding=4>\n";
print "<tr><td><b>$text{'ifcs_name'}</b></td>\n";
print "<td>", &get_adaptername($b->{'irq'}), "</td> </tr>\n";
print "<tr><td><b>$text{'ifcs_mac'}</b></td>\n";
print "<td>$b->{'ether'}</td> </tr>\n";
print "<tr><td><b>$text{'ifcs_ip'}</b></td>\n";
#printf "<td><input type=radio name=iprdn %s value='dhcp'>$text{'from_dhcp'}</td> </tr>\n", ($b->{'dhcp'})?"checked":"";
#printf "<tr><td></td><td><input type=radio name=iprdn %s value='bootp'>$text{'from_bootp'}</td> </tr>\n", ($b->{'bootp'})?"checked":"";
printf "<td><input type=hidden name=iprdn %s value='static'><input class=text name=ipin value='$b->{'address'}'></td> </tr>\n", ((!$b->{'dhcp'})&&!($b->{'bootp'}))?"checked":"";
print "<tr><td><b>$text{'ifcs_mask'}</b></td>\n";
print "<td><input class=text name=maskin size=25 value='$b->{'netmask'}'></td> </tr>\n";
#print "<tr><td><b>$text{'ifcs_broadcast'}</b></td>\n";
#print "<td><input class=text name=broadcastin size=25 value='$b->{'broadcast'}'></td> </tr>\n";
#print "<tr><td><b>$text{'ifcs_gateway'}</b></td>\n";
#print "<td><input class=text name=gatewayin size=25 value='$b->{'gateway'}'></td> </tr>\n";
print "<tr><td colspan=2><input class=button1 type=submit name=savebtn value='$text{'submit'}'></td></tr>\n";
print "</table></form>\n";

&footer("index.cgi", $text{'interface_return'});
}
elsif($b->{'virtual'} eq "SLAVE")
{
&header($text{'edit_interface_title'}, "", "editinterface", 0, 1);
#print "<hr>\n";
print "<form action=save_interface.cgi method=post onsubmit='document.forms[0].savebtn.disabled = true;'>\n";
print "<input type=hidden name=eth value='$in{'eth'}'>\n";
print "<table class=mode1 border=0 cellspacing=0 cellpadding=4>\n";
print "<tr><td><b>$text{'ifcs_name'}</b></td>\n";
print "<td>", &get_adaptername($b->{'irq'}), "</td> </tr>\n";
print "<tr><td><b>$text{'ifcs_mac'}</b></td>\n";
print "<td>$b->{'ether'}</td> </tr>\n";
print "<tr><td><b>$text{'ifcs_ip'}</b></td>\n";
printf "<td><input type=radio name=iprdn %s value='dhcp'>$text{'from_dhcp'}</td> </tr>\n", ($b->{'dhcp'})?"checked":"";
printf "<tr><td></td><td><input type=radio name=iprdn %s value='bootp'>$text{'from_bootp'}</td> </tr>\n", ($b->{'bootp'})?"checked":"";
printf "<tr><td></td><td><input type=radio name=iprdn %s value='static'><input class=text name=ipin value='$b->{'address'}'></td> </tr>\n", ((!$b->{'dhcp'})&&!($b->{'bootp'}))?"checked":"";
print "<tr><td><b>$text{'ifcs_mask'}</b></td>\n";
print "<td><input class=text name=maskin size=25 value='$b->{'netmask'}'></td> </tr>\n";
#print "<tr><td><b>$text{'ifcs_broadcast'}</b></td>\n";
#print "<td><input class=text name=broadcastin size=25 value='$b->{'broadcast'}'></td> </tr>\n";
#print "<tr><td><b>$text{'ifcs_gateway'}</b></td>\n";
#print "<td><input class=text name=gatewayin size=25 value='$b->{'gateway'}'></td> </tr>\n";
#print "<tr><td colspan=2><input class=button1 type=submit name=savebtn value='$text{'submit'}'></td></tr>\n";
print "</table></form>\n";
#print "<hr>\n";
&footer("index.cgi", $text{'interface_return'});
}

